package com.xuelang.pipeline.entry.task;

import com.xuelang.pipeline.app.task.TaskService;
import com.xuelang.pipeline.client.common.constant.DictDTO;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.task.ITaskService;
import com.xuelang.pipeline.client.task.dto.DeployTaskConfigDTO;
import com.xuelang.pipeline.client.task.dto.TaskDTO;
import com.xuelang.pipeline.client.task.dto.TaskQuery;
import com.xuelang.pipeline.client.task.dto.TaskVerifyUserPageQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 流水线任务服务web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Slf4j
@RestController
@RequestMapping("/task")
public class TaskController implements ITaskService {

    @Autowired
    private TaskService taskService;

    @Override
    public ApiResult<PageRecord<TaskDTO>> pageTaskList(PageParam<TaskQuery> dtoPageParam) {
        return ApiResult.success(taskService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<TaskDTO>> conditionalTaskList(TaskQuery taskQuery) {
        return ApiResult.success(taskService.list(taskQuery));
    }

    @Override
    public ApiResult<Boolean> addTask(TaskDTO taskDTO) {
        return ApiResult.success(taskService.add(taskDTO));
    }

    @Override
    public ApiResult<Boolean> updateTask(TaskDTO taskDTO) {
        return ApiResult.success(taskService.update(taskDTO));
    }

    @Override
    public ApiResult<Boolean> deleteTask(String uuid) {
        return ApiResult.success(taskService.delete(uuid));
    }

    @Override
    public ApiResult<TaskDTO> queryTask(String uuid) {
        return ApiResult.success(taskService.query(uuid));
    }

    @Override
    public ApiResult<List<DictDTO>> queryRedLineTaskDict() {
        return ApiResult.success(taskService.redLineTaskDict());
    }

    @Override
    public ApiResult<String> queryDeployAdvancedConfig(DeployTaskConfigDTO deployTaskConfigDTO) {
        return ApiResult.success(taskService.queryDeployAdvancedConfig(deployTaskConfigDTO));
    }

    @Override
    public ApiResult<PageRecord<DictDTO>> queryVerifyUserDict(TaskVerifyUserPageQuery pageParam) {
        return ApiResult.success(taskService.queryVerifyUserDict(pageParam));
    }

    @Override
    public ApiResult<List<DictDTO>> queryDeployTaskDict() {
        return ApiResult.success(taskService.queryDeployTaskDict());
    }
}